
<html ng-app="app">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<link href="../../build/common/base.css" rel="stylesheet">
	<script type="text/javascript" src="../../build/common/base.js"></script>
	<script type="text/javascript" src="../../build/common/ngEdit.js"></script>

	<script type="text/javascript">
        var type = $.getParam("type")
        var app = angular.module('app', [ 'baseDirective' ]);
        app.controller("ctrl", [ '$scope', 'baseService', 'ArrayToolService', function($scope, baseService, ArrayToolService) {
            $scope.ArrayTool = ArrayToolService;
            $scope.tableName = $.getParam("tableName")||"";

            $scope.init = function() {
                $scope.parentScope = window.passData.parentScope;
                //获取bo信息
                var url = __ctx + "/form/formDef/templateData?boKey=" + $scope.parentScope.data.boKey+"&type="+type;
                var defer = baseService.post(url, {});
                $.getResultData(defer, function(data) {
                    $scope.data = data;
                });
            };

            //生成html
            $scope.createHtml = function() {
                var url = __ctx + "/form/formDef/createHtml?boKey=" + $scope.parentScope.data.boKey+"&formType="+type+"&isSubTable="+$scope.tableName;
                var defer = baseService.post(url, $scope.data);
                $.getResultData(defer, function(data) {
                    $scope.parentScope.$apply(function() {
                        if($scope.tableName){
                            var editor = $scope.abEditor;
                            $scope.parentScope.data.html = $scope.parentScope.data.html.substring(0,$scope.parentScope.data.html.lastIndexOf("</div>")) + data + "</div>";
                        }else{
                            $scope.parentScope.data.html = data;
                        }
                    });
                    $.Dialog.close(window);
                });
            };
        } ]);

        function createHtml() {
            AngularUtil.getScope().createHtml();
        }
	</script>
</head>
<body ng-controller="ctrl" ng-init="init()">
<form name="form">
	<table class="form-table form-table-list form-table-th-l">
		<tr>
			<th class="t-a-l">表名</th>
			<th>类型</th>
			<th>模板</th>
		</tr>
		<tr ng-repeat="item in data" ng-if="item.typeDesc!='一对一' && (!tableName || tableName===item.tableKey)">
			<td>{{item.tableComment}}
			</th>
			<td>{{item.typeDesc}}</td>
			<td>
				<select class="form-control" ng-init="item.templateKey ? '' : item.templateKey=item.templates[0].key" ng-model="item.templateKey" ng-options="m.key as m.name for m in item.templates">
				</select>
			</td>
		</tr>
	</table>
</form>
</body>
</html>